#pragma once

#include <array>
#include <vector>

namespace jianzhi_056
{

class Solution
{
public:
    std::vector<int> singleNumbers(const std::vector<int>& nums)
    {
        int a_xor_b = 0;
        for (auto v : nums)
            a_xor_b ^= v;

        long long bit = ((a_xor_b ^ (a_xor_b - 1)) + 1) >> 1;
        int a = a_xor_b;
        int b = a_xor_b;
        for (auto v : nums) {
            if (v & bit)
                a ^= v;
            else
                b ^= v;
        }
        return {a,b};
    }

    int singleNumber(const std::vector<int>& nums)
    {
        std::array n{0, 0};
        for (auto v : nums) {
            int c = n[0] & v;
            n[0] ^= v;
            for (int i = 1; c != 0; i ^= 1) {
                int ci = n[i] & c;
                n[i] ^= c;
                c = ci;
            }
        }
        return n[0] ^ (n[0] & n[1]);
    }
};

}  /* namespace jianzhi_056 */
